{% extends 'install.html' %}
{% block cs %}
<style type="text/css">
	.fff a{
	color: #fff;
}
</style>
<script type="text/javascript">
	$(document).ready(function() {
		$("#piliang").click(function(e){
			$("input[name='find']").each(function(){
			if($(this).prop("checked")){     
    			$(this).prop("checked",false);     
         	}     
   			else{     
    			$(this).prop("checked",true);
    			e.preventDefault();
    			$.scojs_message('批量操作根据统计200台机器需要30秒左右，请耐心等待', $.scojs_message.TYPE_ERROR);
   			}        
		})
		})
		$("#zhixing").click(function(){
			var string = '';
			var $btn = $(this).button('loading');
			$("input[name='find']:checked").each(function(){
				string += $(this).val() + ","
			})
			if (string == ''){
				alert("Nothing Select");
				$btn.button('reset');
			}
			else{
				$.post("{% url "piliang" %}",{
					server_list:string 
				},
				function(data,status){
					data=JSON.parse(data);
					if (data.code == 0 ){
						alert("添加成功");
						 window.location.href="{% url "exe" %}";
					}
					else if(status != "success") {
						$(".error").html('<div class="alert alert-warning alert-dismissible fade in" role="alert"><button type="button" class="close" data-dismiss="alert"><span aria-hidden="true">×</span><span class="sr-only">Close</span></button><strong>注意  !!</strong><p>批量添加队列失败,服务器错误</p></div>');
					}
					else if (data.code != 0 ){
						$(".error").html('<div class="alert alert-warning alert-dismissible fade in" role="alert"><button type="button" class="close" data-dismiss="alert"><span aria-hidden="true">×</span><span class="sr-only">Close</span></button><strong>注意  !!</strong><p>批量添加队列失败，请重新刷新页面再尝试</p></div>');
					}
				})

			}
		})
	})
</script>
{% endblock %}
{% block list %}
<div class="error"></div>
<table id="myTable" class="table table-hover">
	<thead>
	<tr>
		<th>SN</th>
		<th>DHCP_IP</th>
		<th>详情</th>
		<th>操作</th>
		<th>状态</th>
		<th id="piliang" style="color:#5bc0de">全选</th>
		<th>可删除</th>
	</tr>
	</thead>
	<tbody>
		{% for i in forms %}
	<tr>
		<td>{{ i.sn }}</td>
		<td>{{ i.ipaddr }}</td>
		<td><button type="button" class="btn btn-info btn-sm"  data-trigger="modal" data-title="配置信息" data-cssclass="info" href="/info/{{ i.id }}" id="{{i.id}}">详细信息</button></td>
		{% if i.status %}
		<td class="fff"><a class="btn btn-success btn-sm" role="button" href="/online/{{i.id}}">装机</a></td>
		<td class="fff"><a class="btn btn-primary btn-sm" role="button" href="/lock/{{i.id}}/{{i.status}}">锁定</a></td>
		<td><input type="checkbox" name="find" value="{{i.id}}"></td>
		{% else %}
		<td><button type="button" class="btn btn-danger btn-sm" disabled="disabled">禁用</button></td>
		<td class="fff"><a class="btn btn-warning btn-sm" role="button" href="/lock/{{i.id}}/{{i.status}}">解锁</a></td>
		<td><input disabled="disabled" type="checkbox"></td>
		{% endif %}
		<td><a data-trigger="confirm" data-cssclass="del" class="btn btn-default btn-sm" href="/del/{{i.id}}">删除</a></td>
	</tr>
	{% endfor %}
	</tbody>
</table>
<button id="zhixing" class="btn  btn-default">批量加入队列</button>
{% endblock %}